import {defineStore} from "pinia";
import {Story} from "@/dto/Main/Story.ts";
import {SetMeal} from "@/dto/Main/SetMeal.ts";
import {Page} from "@/common/Page.ts";
import {StoryApi} from "@/api/Main/StoryApi.ts";

const STORE = "Story";
export const useStoryStore = defineStore(STORE, {
    state: () => {
        return {
            story:new Story(),
            tableData:[] as Array<Story>,
            pageConfig:Page.initPage,
            api:new StoryApi()
        }
    },
    actions: {
        getStory(){
            return this.story
        },
        setStory(story:Story){
            this.story = story
        },
        async initTableData() {
            let search = new SetMeal(this.pageConfig.pageSize, this.pageConfig.page)
            let result = await this.api.pageAll(search)
            this.tableData = result.data?.content ?? []
            this.pageConfig.total = result.data?.totalElements ?? 0;
        },
        getApi(){
            return this.api
        },
        getPageConfig(){
            return this.pageConfig
        },
        getTableData(){
            return this.tableData
        }
    }
})